<template>
  <div>
    <el-form
      ref="searchForm"
      class="searchForm"
      :model="searchForm"
      label-width="auto"
    >
      <el-row :gutter="12">
        <!--        合计24份  -->
        <el-col :span="6">
          <el-form-item prop="queryCondition.dealerCode" label="交易者编号">
            <el-input v-model.trim="searchForm.queryCondition.dealerCode">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.dealTimeStart" label="起始时间">
            <el-date-picker v-model="searchForm.queryCondition.dealTimeStart">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.dealTimeEnd" label="终止时间">
            <el-date-picker v-model="searchForm.queryCondition.dealTimeEnd">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-edit"
          @click="queryByCondition(1)"
          >查询</el-button
        >
        <el-button
          type="warning"
          icon="el-icon-remove"
          @click="() => $refs.searchForm.resetFields()"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!--        {
      "dealBillId": 65,
      "supplierCode": "8114427",
      "consumerCode": "8116804",
      "dealTime": "2021-09-17T16:12:14",
      "quantity": 12,
      "dealState": "succeeded",
      "dealNote": "招久付出",
      "version": 0
    },-->
    <el-table :data="results" class="resultsTable" stripe height="400px">
      <el-table-column
        prop="dealBillId"
        label="ID"
        width="60px"
      ></el-table-column>
      <!--      <el-table-column prop="dealTime" label="交易时间" width="200px" align="center">-->
      <!--      </el-table-column>-->
      <el-table-column
        label="交易时间"
        :formatter="dealTimeFormat"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="supplierCode" label="提供者编号"></el-table-column>
      <el-table-column prop="consumerCode" label="获得者编号"></el-table-column>
      <el-table-column
        prop="quantity"
        label="交易数量"
        align="center"
      ></el-table-column>
      <el-table-column
        :formatter="dealStateFormat"
        label="交易状态"
      ></el-table-column>
      <el-table-column prop="dealNote" label="交易备注"></el-table-column>

      <el-table-column width="180px" fixed="left">
        <template slot-scope="props">
          <el-button
            class="el-button--mini"
            type="warning"
            icon="el-icon-edit"
            @click="openById(props.row.dealBillId)"
            >编辑</el-button
          >
          <el-button
            class="el-button--mini"
            type="danger"
            icon="el-icon-edit"
            @click="deleteById(props.row.dealBillId)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :page-size="searchForm.pageSize"
      :current-page="searchForm.pageNum"
      @current-change="queryByCondition"
      layout="total, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>

<script>
// import New from './components/New.vue';
export default {
  name: "DealBill",
  components: {
    // New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",
      searchForm: {
        pageNum: -1,
        pageSize: 10,
        queryCondition: {
          dealerCode: "",
          dealTimeStart: null,
          dealTimeEnd: null,
        },
      },
      total: 0,
      /*    {
      "dealBillId": 65,
      "supplierCode": "8114427",
      "consumerCode": "8116804",
      "dealTime": "2021-09-17T16:12:14",
      "quantity": 12,
      "dealState": "succeeded",
      "dealNote": "招久付出",
      "version": 0
    },*/
      results: [],
    };
  },
  computed: {
    dealStates() {
      return this.$store.state.dealStates;
    },
    // sampleC() {
    //     return this.sampleD+'--';
    // }
  },
  created() {},
  mounted() {
    this.queryByCondition(1);
  },
  methods: {
    sampleM() {},
    queryByCondition(pageNum) {
      if (pageNum) this.searchForm.pageNum = pageNum;
      // this.$message.success(JSON.stringify(this.searchForm))
      this.$http({
        method: "post",
        url: "/ceto/dealBill/query",
        data: this.searchForm,
      }).then(
        (res) => {
          this.total = res.data.total;
          this.results = res.data.results;
        },
        (error) => {
          this.$message.warning("query mistake：" + error.response.status);
        }
      );
    },
    dealTimeFormat(row) {
      // console.log(row.dealTime);
      //2021-09-17T15:36:27
      let t = new Date(row.dealTime);
      // return t.getFullYear()+"年"+t.getMonth()+"月"+t.getDay()+"日";
      return `${t.getFullYear()}年${t.getMonth()}月${t.getDay()}日`;
    },
    dealStateFormat(row) {
      /*  {
    "value": "willing",
    "text": "未交易",
    "index": 0
  },*/
      let r = this.dealStates.find((x) => x.value === row.dealState);
      return r ? r.text : "N/A";
    },
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<!--<style scoped>-->
<style lang="scss" scoped></style>
